/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2009>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.IO;
using WIA;
using System.Runtime.InteropServices;

namespace MyPhotoIndex.Importer.CameraImageAcquisition
{
    public abstract class ImagingDevice
    {
        public event EventHandler<ImagingDeviceImageTransferEventArgs> ThumbnailDownloadEvent;

        private string m_manufacturer;
        private string m_description;
        private string m_name;

        private List<IAcquiredImage> m_imageList = new List<IAcquiredImage>();

        public static ReadOnlyCollection<ImagingDevice> List
        {
            get
            {
                List<ImagingDevice> list = new List<ImagingDevice>();
                DeviceManagerClass c = new DeviceManagerClass();
                foreach (object o in c.DeviceInfos)
                {
                    DeviceInfoClass deviceInfoClass = (DeviceInfoClass)Marshal.CreateWrapperOfType((IDeviceInfo)o, typeof(DeviceInfoClass));
                    DigitalCamera camera = new DigitalCamera(deviceInfoClass);
                    list.Add(camera);
                }

                DriveInfo[] allDrives = DriveInfo.GetDrives();
                foreach (DriveInfo driveInfo in allDrives)
                {
                    if (driveInfo.DriveType == DriveType.Removable &&
                        driveInfo.IsReady == true)
                    {
                        RemovableDrive drive = new RemovableDrive(driveInfo);
                        list.Add(drive);
                    }
                }

                return list.AsReadOnly();
            }
        }

        public override string ToString()
        {
            return string.IsNullOrEmpty(Description) ? Name : Description;
        }

        public ReadOnlyCollection<IAcquiredImage> Images
        {
            get
            {
                return m_imageList.AsReadOnly();
            }
        }

        protected List<IAcquiredImage> ImageList
        {
            get
            {
                return m_imageList;
            }
        }

        public string Name
        {
            get { return m_name; }
            protected set { m_name = value; }
        }

        public string Manufacturer
        {
            get { return m_manufacturer; }
            protected set { m_manufacturer = value; }
        }

        public string Description
        {
            get { return m_description; }
            set { m_description = value; }
        }

        protected void InvokeThumbnailDownloadEvent(ImagingDeviceImageTransferEventArgs imagingDeviceImageTransferEventArgs)
        {
            if (ThumbnailDownloadEvent != null)
            {
                ThumbnailDownloadEvent.Invoke(this, imagingDeviceImageTransferEventArgs);
            }
        }

        public abstract void DownloadImages();
    }
}
